*************************************************
*Replicate figures and tables presented in Ma, Wenting. 2024. "Employer Dominance and Worker Earnings in Finance." Review of Corporate Finance Studies

*Author: Wenting Ma (UMass Amherst)
*Date: July 6 2024


*NOTE: 
*  -The datasets firmid_qtr_regsample_1990_2013, firmid_cz_qtr_regsample_1990_2013, and pik_yr_regsample_1990_2013 were created using administrative datasets from the US Census and cannot be disclosed. Instead, pseudo samples are provided and used here. These pseudo samples maintain the same structure as the original datasets but contain pseudo numbers, resulting in different estimates from those reported in the paper.

*************************************************

set more off 
clear all 
********************************************************************************
* DIRECTORIES
********************************************************************************	
	global DIR_MAIN = "C:\Users\wentingma\Dropbox\Research\MarketPower_FinanceWage\RCFS_submission\RCFS_Ma_2024\replication" 
    global DIR_DATA = "${DIR_MAIN}\data\"
	global DIR_TEMP = "${DIR_MAIN}\temp\"
	global DIR_OUTPUT = "${DIR_MAIN}\output\"
	global DIR_LOG = "${DIR_MAIN}\logs\"

********************************************************************************
* PROGRAMS
********************************************************************************
*** PROGRAM for defining panel ids
capture program drop define_panel 
program define_panel 
	if "${level}"=="firmid_qtr"{
		dis "--------Panel is at firm-year-quarter level----------------"
		dis "--------period=year-quarter--------------------------------"
		dis "--------id1=firm--------------------------------"
		
		global time_level "year quarter"
		global unit_level "firmid"
		global firm_ind "firm_indsic"
	}
	else if "${level}"=="firmid_cz_qtr"{
		dis "--------Panel is at firm-commuting zone-year-quarter level----------------"
		dis "--------period=year-quarter--------------------------------"
		dis "--------id1=firm-commuting zone--------------------------------"
		global time_level "year quarter"
		global unit_level "firmid czone"
		global firm_ind "firm_czindsic"
	}
	else if "${level}"=="pik_yr"{
		dis "--------Panel is at individual-year level----------------"
		dis "--------period=year--------------------------------"
		dis "--------id1=worker--------------------------------"
		global time_level "year"
		global unit_level "pik"
		global firm_ind "firm_indsic"
	}
end


*** PROGRAM for t-test of means in 2 groups ***
capture program drop ttest_wo_weight 
program ttest_wo_weight , eclass
	version 8
		syntax varlist [if] [in], by(varname) [ * ]
		marksample touse
		markout `touse' `by'
		tempname Mean_0 Mean_1 d d_se d_t d_p sd_0 sd_1 N_0 N_1 Mean sd N d_se_clst  d_p_clst
		foreach var of local varlist {
			*** t-test
			ttest `var' if `touse', by(`by') `options'
			mat `Mean_0' 	= nullmat(`Mean_0'), 	r(mu_1)
			mat `Mean_1' 	= nullmat(`Mean_1'), 	r(mu_2)
			mat `sd_0' 	= nullmat(`sd_0'), 	r(sd_1)
			mat `sd_1' 	= nullmat(`sd_1'), 	r(sd_2)
			mat `d' 	= nullmat(`d'), 	r(mu_2) - r(mu_1)
			mat `d_se' 	= nullmat(`d_se'), 	r(se)
			mat `d_t' 	= nullmat(`d_t'), 	r(t)
			mat `d_p' 	= nullmat(`d_p'), 	r(p)
			mat `N_0' 	= nullmat(`N_0'), 	r(N_1)
			mat `N_1' 	= nullmat(`N_1'), 	r(N_2)
			*** stats for all
			sum `var' if `touse',   `options'
			mat `Mean' 	= nullmat(`Mean'), 	r(mean)			
			mat `sd' 	= nullmat(`sd'), 	r(sd)			
			mat `N' 	= nullmat(`N'), 	r(N)
			*** t -  clustered st errors
			reg `var' `by' if `touse', $semethod vce(cluster firmid)
			matrix V = e(V)
			scalar temp = sqrt(V[1,1])
			mat `d_se_clst' = nullmat(`d_se_clst'), temp
			scalar p_temp = ( 2 * ttail(e(df_r), abs(_b[`by'] / _se[`by'])))
			di p_temp
			mat `d_p_clst' 	= nullmat(`d_p_clst'),  p_temp
		}
		foreach mat in Mean_0 Mean_1 d d_se d_t d_p  sd_0 sd_1 N_0 N_1  Mean sd N d_se_clst d_p_clst {
			mat coln ``mat'' = `varlist'
		}
		tempname b V
		mat `b'  = `Mean_0'*0
		mat `V'  = `b''*`b'
		eret post `b' `V'
		eret local cmd "ttest_wo_weight"
		foreach mat in Mean_0 Mean_1 d d_se d_t d_p sd_0 sd_1 N_0 N_1 Mean sd N d_se_clst d_p_clst {
			eret mat `mat' = ``mat''
		}		
	
end


cap log close
log using "${DIR_LOG}/replication_Ma2024_RCFS.log", replace

********************************************************************************
* GLOBALS FOR SAMPLE 
********************************************************************************
global year_min 1990 
global year_max 2013
global sector_groups0 fin2emp //omit non-fin
global sector_groups1 trade_exfin fin2emp //omit nontradable (compare with non-tradable sector) 
global sector_groups2 am cb ins serv manuf other //omit htech  

global cond0 "if year>=$year_min"  //full sample period
global cond1 "if year<2007" //pre crisis
global cond2 "if year>=2007 & year<=2009" //during crisis 
global cond3 "if year>=2010" //post crisis 

 
********************************************************************************
* ANALYSIS
********************************************************************************

**# Figure 1 earnings by MP quartiles
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
global yvar_list lg_avg_rearn //log of average real earns
local fin fin2emp //fin2emp=1 if a firm's major industry (based on employment) is finance.
local othercontrol lag_lg_firmage_emp lag_male_shr lag_white_shr lag_college_shr
local i 2_emp //define # of SIC digit and how firm industries are classified. 2_emp represents 2-digit SIC defined using mod employment
local mkp_x lag_empshr_sic`i' 
local cluster id1
local filename ${DIR_OUTPUT}\Figure1
capture rm `filename'.xls 
capture rm `filename'.txt 
 
				use "${DIR_DATA}\`s'",clear	
				* generate quartiles of firm relative size
				sum `mkp_x',d
				capture drop qt_mkp
				capture drop mkp_Q*
				xtile qt_mkp=`mkp_x',n(4)
				tab qt_mkp,gen(mkp_Q)
				drop qt_mkp
				label var mkp_Q4 "the 4th quatile of `mkp_x''"
				 

				drop mkp_Q1 //omit first quartile from the regressions
				foreach y of global yvar_list{
				
				cap drop b_fin* se_fin* b_nfin* se_nfin*
				forvalue j=2(1)4{
				gen b_finQ`j'=.
				gen se_finQ`j'=. 
				gen b_nfinQ`j'=.
				gen se_nfinQ`j'=.
				}
					
				reghdfe `y' mkp_Q* `othercontrol' if `fin'==1 ,absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
				outreg2 using `filename'.xls, keep(mkp_Q*) ///
				addtext(SIC-Time FE, YES, Workforce composition, YES, lag_lg_firmage_emp , YES,  Sample,`s', subsample, `fin'==1) 
				forvalue j=2(1)4{
				replace b_finQ`j'=_b[mkp_Q`j']
				replace se_finQ`j'=_se[mkp_Q`j'] 
				}

				reghdfe `y'  mkp_Q* `othercontrol' if `fin'==0 ,absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
				outreg2 using `filename'.xls, keep(mkp_Q*) ///
				addtext(SIC-Time FE, YES, Workforce composition, YES, Firm age, YES,  Sample,`s', subsample, `fin'==0) 
				forvalue j=2(1)4{
				replace b_nfinQ`j'=_b[mkp_Q`j']
				replace se_nfinQ`j'=_se[mkp_Q`j'] 
				}
				
				}
 
				**plot the coefficients of mkp_Q from above estimation	
				keep b_* se_* 
				duplicates drop  
				gen spec_n=1
				reshape long b_fin se_fin b_nfin se_nfin, i(spec_n) j(_) string 
				rename _ Q
				
				gen qt=1.2 if Q=="Q2"
				replace qt=2 if Q=="Q3"
				replace qt=2.7 if Q=="Q4"

				foreach sec in fin nfin{
				cap gen yu_b_`sec' =  b_`sec' + 1.96*se_`sec'
				cap gen yl_b_`sec' =  b_`sec' - 1.96*se_`sec'
				}


				local var b
				twoway (scatter `var'_fin qt, msymbol(o) mcolor(gs2)) (rcap yu_`var'_fin yl_`var'_fin qt, lc(gs2) lpattern(solid)) (line `var'_fin qt,lc(gs2) lpattern(dash)) ///
					   (scatter `var'_nfin qt, msymbol(o) mcolor(gs8)) (rcap yu_`var'_nfin yl_`var'_nfin qt, lc(gs8) lpattern(solid)) (line `var'_nfin qt,lc(gs8) lpattern(dash)), xlabel( 1 `" "' 1.2 `"2nd Quartile"' 2 `"3rd Quartile"' 2.7 `"4th Quartile"' 3 `" "', labsize(small) tstyle(major_notick))  ///  
					   ytitle("Earning Premium Over 1st Quartile of Relative Size", size(small)) xtitle("") ylabel(#20,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(univarite_nfin_2d,replace) legend(order(1 4) label(1 "Finance") label(4 "Non-finance") size(small)) 
				graph export "`filename'.pdf",as(pdf) replace
				
 

**# Figure 2 earnings & MP by period  
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local othercontrol lag_lg_firmage_emp lag_male_shr lag_white_shr lag_college_shr
local i 2_emp
local mkp_x lag_empshr_sic`i' 
global group ${sector_groups0}		
local cluster id1 //cluster at firm  	 	
local y lg_avg_rearn  
global cond_list 1 2 3  //go through each subsample one-by-one
local filename ${DIR_OUTPUT}\Figure2
capture rm `filename'.xls 
capture rm `filename'.txt 

				use "${DIR_DATA}\`s'",clear						
 			 
				foreach var of global group{
					cap drop `var'X`mkp_x'
					gen `var'X`mkp_x'=`var'*`mkp_x'		
				}
							
		        foreach c of global cond_list{	
					
					reghdfe `y' `mkp_x' *X`mkp_x' $group  `othercontrol' ${cond`c'},absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
					outreg2 using "`filename'.xls", ///
					addtext(SIC-Time FE, YES, Workforce composition, YES, Firm age, YES,  Sample,`s', subsample, ${cond`c'}) keep(`mkp_x' *X`mkp_x') 
					
					cap drop b_period`c' se_period`c'
					gen b_fin`c'=_b[fin2empX`mkp_x'] 
					gen se_fin`c'=_se[fin2empX`mkp_x'] 
					gen b_nfin`c'=_b[`mkp_x'] 
					gen se_nfin`c'=_se[`mkp_x'] 
				 
				}  //end of c list
				cap drop *X*
				
				
				**plot the coefficients of *X`mkp_x' from above estimation	
				keep b_* se_* 
				duplicates drop  
				gen spec_n=1
				reshape long b_fin se_fin b_nfin se_nfin, i(spec_n) j(_)  
				rename _ period 
 
				local var b
				foreach sec in fin nfin{
				 
				cap gen yu_`var'_`sec' =  `var'_`sec' + 1.96*se_`sec'
				cap gen yl_`var'_`sec' =  `var'_`sec' - 1.96*se_`sec'

				 
				twoway (scatter `var'_`sec' period, msymbol(o) mcolor(gs2)) (rcap yu_`var'_`sec' yl_`var'_`sec' period, lc(gs2) lpattern(solid))  ///
					   , xlabel(1 `"1990-2006"' 2 `"2007-2009"' 3 `"2010-2013"', labsize(small))  ///  
					   ytitle("", size(vsmall)) xtitle("") ylabel(-0.05(0.01)0.05,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(byperiod_fin_`var',replace) legend(order(1 2) label(1 "Coefficient Estimate") label(2 "95% CI") size(vsmall)) yline(0,lcolor(red) lpattern(dash)) xscale(range(0.5 3.5))
					   graph export "`filename'_`sec'.pdf",as(pdf) replace
				}

				 
 
  
**# Figure 3 earnings & MP by subsector & Table 8 earnings & MP by tradable vs non-tradable 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local othercontrol lag_lg_firmage_emp lag_male_shr lag_white_shr lag_college_shr
local i 2_emp
local mkp_x lag_empshr_sic`i'		
local cluster id1 //cluster at firm  	 	
local y lg_avg_rearn 
local c 0 //include all years  
global sector_list  2
global cond_list 0  //go through each subsample one-by-one
local filename ${DIR_OUTPUT}\Figure3_Table8
capture rm `filename'.xls 
capture rm `filename'.txt 
 
				use "${DIR_DATA}\`s'",clear
				foreach g of global sector_list{ //sector group list
							sum ${sector_groups`g'}
							ds ${sector_groups`g'}
							global group `r(varlist)'
									
									 
							foreach var of global group{
								cap drop `var'X`mkp_x'
								gen `var'X`mkp_x'=`var'*`mkp_x'		
							}
					
							reghdfe `y' `mkp_x' *X`mkp_x' $group  `othercontrol' ${cond`c'},absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
							outreg2 using "`filename'.xls", ///
							addtext(SIC-Time FE, YES, Workforce composition, YES, Firm age, YES,  Sample,`s', subsample, ${cond`c'}) keep(`mkp_x' *X`mkp_x') 
							
							if "`g'"=="2"{
								foreach var of global group{
									cap drop b_`var' se_`var'
									gen b_`var'=_b[`var'X`mkp_x']
									gen se_`var'=_se[`var'X`mkp_x']
								} //end of var 						
								
							} //end of if

					 
						cap drop *X`mkp_x' 	
					
			    } // end of sector group g


				keep b_* se_* 
				duplicates drop  
				gen spec_n=1
				reshape long b se, i(spec_n) j(_) string
				rename _ sec 
				gen ind=1 if sec=="_am"
				replace ind=2 if sec=="_cb"
				replace ind=3 if sec=="_ins"
				replace ind=4 if sec=="_serv"
				replace ind=5 if sec=="_manuf"
				replace ind=6 if sec=="_other"

				local var b
				cap gen yu_`var' =  `var' + 1.96*se
				cap gen yl_`var' =  `var' - 1.96*se


				twoway  (scatter `var' ind, msymbol(o) mcolor(gs2)) (rcap yu_`var' yl_`var' ind, lc(gs2) lpattern(solid))  /// 
					   , xlabel(1 `""Broker, Dealer," "Exchange Services""' 2 `""Banking and Credit" "Institutions""' 3 `"Insurance"' 4 `"Service"' 5 `"Manufacturing"' 6 `"Other"', labsize(vsmall))  ///  
					   ytitle("", size(vsmall)) xtitle("") ylabel(#20,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(subsector_`var',replace) legend(order(1 2) label(1 "Coefficient Estimate") label(2 "95% CI") size(vsmall)) yline(0,lcolor(red) lpattern(dash)) xscale(range(0.5 3.5))
					  
				graph export "${DIR_OUTPUT}\Figure3.pdf",as(pdf) replace
	
	


**# Figure 4 lerner and rev/worker by period 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local othercontrol lag_lg_firmage_emp lag_male_shr lag_white_shr lag_college_shr
local i 2_emp
local mkp_x lag_empshr_sic`i' 
global group ${sector_groups0}		
local cluster id1 //cluster at firm  	 	
global yvar_list lerner lgs_emp      
global cond_list 1 2 3  //go through each subsample one-by-one
local filename ${DIR_OUTPUT}\Figure4
capture rm `filename'.xls 
capture rm `filename'.txt 		
			 
			use "${DIR_DATA}\`s'",clear						
 			 
				foreach var of global group{
					cap drop `var'X`mkp_x'
					gen `var'X`mkp_x'=`var'*`mkp_x'		
				}
				
				foreach y of global yvar_list{
					preserve
					foreach c of global cond_list{	
							
					reghdfe `y' `mkp_x' *X`mkp_x' $group  `othercontrol' ${cond`c'},absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
					outreg2 using "`filename'.xls", ///
					addtext(SIC-Time FE, YES, Workforce composition, YES, Firm age, YES,  Sample,`s', subsample, ${cond`c'}) keep(`mkp_x' *X`mkp_x') 
					
					cap drop b_period`c' se_period`c'
					gen b_fin`c'=_b[fin2empX`mkp_x'] 
					gen se_fin`c'=_se[fin2empX`mkp_x'] 
					 
				    }  //end of c list	
					
					**plot the coefficients of *X`mkp_x' from above estimation	
					
					keep b_* se_* 
					duplicates drop  
					gen spec_n=1
					reshape long b_fin se_fin, i(spec_n) j(_)  
					rename _ period 
	 
					local var b
					local sec fin
					cap drop yu_`var'_`sec' yl_`var'_`sec'
					gen yu_`var'_`sec' =  `var'_`sec' + 1.96*se_`sec'
					gen yl_`var'_`sec' =  `var'_`sec' - 1.96*se_`sec'

					twoway (scatter `var'_`sec' period, msymbol(o) mcolor(gs2)) (rcap yu_`var'_`sec' yl_`var'_`sec' period, lc(gs2) lpattern(solid))  ///
						   , xlabel(1 `"1990-2006"' 2 `"2007-2009"' 3 `"2010-2013"', labsize(small))  ///  
						   ytitle("", size(vsmall)) xtitle("") ylabel(#15,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(byperiod_fin_`var',replace) legend(order(1 2) label(1 "Coefficient Estimate") label(2 "95% CI") size(vsmall)) yline(0,lcolor(red) lpattern(dash)) xscale(range(0.5 3.5))
						   graph export "`filename'_`y'.pdf",as(pdf) replace
					 	
				 	restore
				} //end of yvar list 
				
			 
				
								

**# Figure 5 lerner and rev/worker by subsector 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local othercontrol lag_lg_firmage_emp lag_male_shr lag_white_shr lag_college_shr
local i 2_emp
local mkp_x lag_empshr_sic`i'		
local cluster id1 //cluster at firm  	 	
global yvar_list lerner lgs_emp   
local g 2 //decompose sectors 
local c 0  //include all years
local filename ${DIR_OUTPUT}\Figure5
capture rm `filename'.xls 
capture rm `filename'.txt 

				use "${DIR_DATA}\`s'",clear
										
				sum ${sector_groups`g'}
				ds ${sector_groups`g'}
				global group `r(varlist)'
						
						 
				foreach var of global group{
					cap drop `var'X`mkp_x'
					gen `var'X`mkp_x'=`var'*`mkp_x'		
				}
						
						 
				foreach y of global yvar_list{
					
					reghdfe `y' `mkp_x' *X`mkp_x' $group  `othercontrol' ${cond`c'},absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
					outreg2 using "`filename'.xls", ///
					 addtext(SIC-Time FE, YES, Workforce composition, YES, Firm age, YES,  Sample,`s', subsample, ${cond`c'}) keep(`mkp_x' *X`mkp_x') 		

				
				preserve
				*Plot coefficients of *X`mkp_x' from above estimation
				foreach var of global group{
					cap drop b_`var' se_`var'
					gen b_`var'=_b[`var'X`mkp_x']
					gen se_`var'=_se[`var'X`mkp_x']
				} //end of var 	
								
								
				keep b_* se_* 
				duplicates drop  
				gen spec_n=1
				reshape long b se, i(spec_n) j(_) string
				rename _ sec 
				
				gen ind=1 if sec=="_am"
				replace ind=2 if sec=="_cb"
				replace ind=3 if sec=="_ins"
				keep if ind!=. //only plot estimates for AM, CB and INS
				 
				local var b
				cap gen yu_`var' =  `var' + 1.96*se
				cap gen yl_`var' =  `var' - 1.96*se

				twoway  (scatter `var' ind, msymbol(o) mcolor(gs2)) (rcap yu_`var' yl_`var' ind, lc(gs2) lpattern(solid))  /// 
					   , xlabel(1 `""Broker, Dealer," "Exchange Services""' 2 `""Banking and Credit" "Institutions""' 3 `"Insurance"', labsize(vsmall))  ///  
					   ytitle("", size(vsmall)) xtitle("") ylabel(#20,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(subsector_`var',replace) legend(order(1 2) label(1 "Coefficient Estimate") label(2 "95% CI") size(vsmall)) yline(0,lcolor(red) lpattern(dash)) xscale(range(0.5 3.5))
					  
				graph export "`filename'_`y'.pdf",as(pdf) replace
				restore
				} //end of yvar list 
 

**# Figure 6 worker FE by subsector & mean of worker FEs by finance vs non-finance described in the text. 
global level pik_yr
local s ${level}_regsample_${year_min}_${year_max}
global time_level "year"
global unit_level "pik"
global firm_ind "firm_indsic"
global yvar_list real_earn  //max log quarterly earn within a given year
global sector_list 1 2 
local filename ${DIR_OUTPUT}\Sec3_2
capture rm `filename'.xls 
capture rm `filename'.txt 

 
		use "${DIR_DATA}\`s'",clear 

		*estimate worker FE 
		reghdfe real_earn,absorb (i.educ_c#c.nage2 i.educ_c#c.nage3  i.educ_c#i.year pfe=i.pik i.firmid) cluster(firmid) keepsin
	     
		save "${DIR_TEMP}/fe",replace
		 
	 
		*Examine pik FE difference by FIN and NON-FIN	
		    local g 1
			sum ${sector_groups`g'}
			ds ${sector_groups`g'}
			global group `r(varlist)'
			
			reg pfe ${group}, vce(cluster firmid)  
			outreg2 using "`filename'.xls", keep($group)  
			
			
		*Examine pik FE difference between fin subsectors and high-tech	& plot the differences
		    local g 2
			sum ${sector_groups`g'}
			ds ${sector_groups`g'}
			global group `r(varlist)'
			
			reg pfe ${group}, vce(cluster firmid)  
			*outreg2 using "`filename'.xls", keep($group)
			 
			
			mat b=e(b)'  
			svmat double b, n(fe) 
			
			mat V=e(V)  
			loca nv=`e(rank)'  
			mat se=J(`nv',1,-9999)  
			forval i=1/`nv' {
				mat se[`i',1]=sqrt(V[`i',`i'])  
			}   
			svmat double se, n(se_fe)  
			
			keep fe1 se_fe1
			drop if fe1==.
			gen ind=_n 
			keep if ind<=3
			rename (fe1 se_fe1) (fe se_fe)
	
			local var fe 
			cap drop yu_`var' yl_`var'
			gen yu_`var' =  `var' + 1.96*se_`var'
			gen yl_`var' =  `var' - 1.96*se_`var'


			twoway  (scatter `var' ind, msymbol(o) mcolor(gs2)) (rcap yu_`var' yl_`var' ind, lc(gs2) lpattern(solid))  /// 
				   , xlabel(1 `""Broker, Dealer," "Exchange Services""' 2 `"Banking and Credit Institutions"' 3 `"Insurance"', labsize(small))  ///  
				   ytitle("", size(vsmall)) xtitle("") ylabel(#15,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(interact_`var',replace) legend(order(1 2) label(1 "Coefficient Estimate") label(2 "95% CI") size(vsmall)) yline(0,lcolor(red) lpattern(dash)) xscale(range(0.5 3.5))
				  
		    graph export "${DIR_OUTPUT}\Figure6.pdf",as(pdf) replace
	   
			


**# Figure 7 Occ Task Intensities  
local s acs_regsample_2001_2013
local cluster pwstate2 //cluster at state here since firm is not observed in ACS
local weight [aw=per_wt] //since ACS is a survey, weight by sampling weight(perwt)*weeks worked(wkswork)*hours worked per week(uhrswork) following Autor, Dorn and Hanson (2013)
global task_list task_abstract task_routine task_manual math_onet1998 socskills_onet1998 //nr_cog_anal nr_cog_pers routine nr_man_phys nr_man_pers  
local filename ${DIR_OUTPUT}\Figure7
 
capture rm `filename'.xls 
capture rm `filename'.txt 

		use "${DIR_DATA}\`s'",clear
			
		rename (task_abstract task_routine task_manual math_onet1998 socskills_onet1998) (Abstract Routine Manual Math Social) //rename variable to store coefficients
		global task_list Abstract Routine Manual Math Social
		
		foreach task of global task_list{
			cap drop sd_`task'
			egen sd_`task'=std(`task')
		} 

        
		**Examine characteristics of finance tasks	
		foreach task of global task_list{	
		cap drop b_`task' se_`task' 
		gen b_`task'=.
		gen se_`task'=.
		
			reghdfe sd_`task' fin `weight', a(i.year#i.educ i.pwstate2#i.year i.race#i.sex i.educ#c.nage2 i.educ#c.nage3) cluster(`cluster') 
			outreg2 using "`filename'.xls", append addtext( YearxEdu, Yes, StatexYear, Yes, Race-Sex FE, Yes, Edu functions, Yes, Weight, `weight') bdec(4) sdec(4)  pdec(4) rdec(3) 
			
		replace b_`task'=_b[fin]
		replace se_`task'=_se[fin]
		}
		
		**plot the coefficients of fin from above estimation	
		keep b_* se_* 
		duplicates drop  
		gen spec_n=1
		reshape long b se, i(spec_n) j(_) string
		rename _ task
		gen category=.
		replace category=1 if task=="_Abstract"
		replace category=2 if task=="_Routine"
		replace category=3 if task=="_Manual"
		replace category=4 if task=="_Math"
		replace category=5 if task=="_Social"
		drop spec_n
		rename b coefficient 
		rename se stderr
		
		gen yu=coefficient+1.96*stderr
		gen yl=coefficient-1.96*stderr 

		twoway (bar coefficient category, barwidth(0.75) bcolor(gs8)) (rcap yu yl category, lc(gs2) lpattern(solid)), xlabel( 1 "Abstract" 2"Routine"  3 "Manual" 4 "Math" 5 "Social", labsize(small) tstyle(major_notick))  yline(0,lcolor(red) lpattern(dash)) ytitle("Marginal Different in Finance", size(small)) xtitle("") ylabel(-0.8(0.1)1,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white)) name(task,replace) legend(off)
		local filename ${DIR_OUTPUT}\Figure7
		graph export "`filename'.pdf", as(pdf) replace
		
		


**# Figure 8 Occ Task Intensity by subsector 
local s acs_regsample_2001_2013
local cluster pwstate2 //cluster at state here since firm is not observed in ACS
local weight [aw=per_wt] //since ACS is a survey, weight by sampling weight(perwt)*weeks worked(wkswork)*hours worked per week(uhrswork) following Autor, Dorn and Hanson (2013)
global task_list task_abstract task_routine task_manual math_onet1998 socskills_onet1998 //nr_cog_anal nr_cog_pers routine nr_man_phys nr_man_pers  
local filename ${DIR_OUTPUT}\Figure8
capture rm `filename'.xls 
capture rm `filename'.txt 

		use "${DIR_DATA}\`s'",clear
		 
		rename (task_abstract task_routine task_manual math_onet1998 socskills_onet1998) (Abstract Routine Manual Math Social) //rename variable to store coefficients
		global task_list Abstract Routine Manual Math Social
		
		foreach task of global task_list{
			cap drop sd_`task'
			egen sd_`task'=std(`task')
		} 

        
		**Examine characteristics of finance tasks	
		foreach task of global task_list{	
		cap drop b_*_`task' se_*_`task' 
		gen b_am_`task'=.
		gen se_am_`task'=.
		gen b_cb_`task'=.
		gen se_cb_`task'=.
		gen b_in_`task'=.
		gen se_in_`task'=.
		
			reghdfe sd_`task' am cb ins manuf serv other `weight', a(i.year#i.educ i.pwstate2#i.year i.race#i.sex i.educ#c.nage2 i.educ#c.nage3) cluster(`cluster') 
			outreg2 using "`filename'.xls", append addtext( YearxEdu, Yes, StatexYear, Yes, Race-Sex FE, Yes, Edu functions, Yes, Weight, `weight') bdec(4) sdec(4)  pdec(4) rdec(3) 
			
		replace b_am_`task'=_b[am]
		replace se_am_`task'=_se[am]
		replace b_cb_`task'=_b[cb]
		replace se_cb_`task'=_se[cb]
		replace b_in_`task'=_b[ins]
		replace se_in_`task'=_se[ins]
		}
		
		**plot the coefficients of fin from above estimation	
		keep b_* se_* 
		duplicates drop  
		gen spec_n=1
		reshape long b se, i(spec_n) j(_) string
		rename _ task
		 
		gen ind=substr(task, 2,2)
		gen len=length(task)
		gen task1=substr(task,4, len-3)
		gen category=.
		replace category=1 if task1=="_Abstract"
		replace category=3 if task1=="_Routine"
		replace category=5 if task1=="_Manual"
		replace category=7 if task1=="_Math"
		replace category=9 if task1=="_Social"
		
		sort category ind
		by category: gen n=_n 
		replace category=category-0.5 if n==1
		replace category=category+0.5 if n==3
		drop spec_n
		
		rename b coefficient 
		rename se stderr
		
		gen yu=coefficient+1.96*stderr
		gen yl=coefficient-1.96*stderr 

		twoway (bar coefficient category if ind=="am", barwidth(0.5) bcolor(gs6)) (bar coefficient category if ind=="cb", barwidth(0.5) bcolor(gs10)) (bar coefficient category if ind=="in", barwidth(0.5) bcolor(gs14)) (rcap yu yl category , lc(gs2) lpattern(solid)), xlabel( 1 "Abstract" 3 "Routine"  5 "Manual" 7 "Math" 9 "Social", labsize(small) tstyle(major_notick))  yline(0,lcolor(red) lpattern(dash)) ytitle("Marginal Different in Finance", size(small)) xtitle("") ylabel(#20,valuelabel labsize(vsmall)) scheme(s2color)  bgcolor(white) graphregion(color(white))  legend(order(1 2 3) label(1 "Broker, Dealer, Exchange Services") label(2 "Banking and Credit Institutions") label(3 "Insurance") size(vsmall))
		graph export "`filename'.pdf", as(pdf) replace
		
		
		
		

**# Table 1 state list 
use "${DIR_DATA}\lehd_states",clear
dis "****LIST OF STATES-YEAR-QUARTERS AVLIABLE IN OUR PROJECT******"
list 
 


**# Table 2 summary stats for all observations AND observations by finance vs non-finance 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local byvar fin2emp //t-test difference by `byvar'	 	
local stats_vars  "avg_rearn avg_f_rearn_p90 rearn_f90_10 sd_rearn empshr_sic2_emp male_shr white_shr college_shr firmage_emp"  
local filename ${DIR_OUTPUT}\Table2
capture rm `filename'.txt 	
			
		use "${DIR_DATA}\`s'",clear 
		keep  `stats_vars' `byvar' $time_level $unit_level
		ttest_wo_weight `stats_vars' , by( `byvar' ) 
		esttab using `filename', append  nomtitle nonumbers noobs varwidth(25) modelwidth(22) 	star(* 0.10 ** 0.05 *** 0.01)		///	
			cells("Mean(fmt(3))  Mean_0  Mean_1  d(star pvalue(d_p))  " "sd(fmt(3) par)  sd_0(par)  sd_1(par)  d_se(par)") ///						 
			title("***Summary statistics of Sample `s',  Mean(Std) for all firms (Column 1) and by ** `byvar'  ** dummy   (Column 2: dummy=0 if it's a non-finance firm, Column 3: dummy=1 if it's a finance firm); difference and significance level between columns 2 and 3 in column 4; All variables have the same number of observations. ***") 	///
			addnotes("* p<0.10    ** p<0.05   *** p<0.01") 
		eststo clear
 

**# Table 3 earnings & MP (2d and 3d)
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local fin fin2emp
local othercontrol lag_lg_firmage_emp  lag_male_shr lag_white_shr lag_college_shr
local cluster id1  //cluster at firm
global yvar_list lg_avg_rearn
 
local filename ${DIR_OUTPUT}\Table3
capture rm `filename'.xls 
capture rm `filename'.txt 

use "${DIR_DATA}\`s'",clear    		
foreach y of global yvar_list{
		 
		*examine finance premium
		reghdfe `y' `fin', absorb(i.period) vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, YES, Workforce composition, NO, Firm age, NO, SIC-YEAR FE, NO, Sample,`s')  
	
	foreach i in 2_emp 3_emp{ //defining market using i-digit of SIC
	
	    local mkp_x lag_empshr_sic`i'  	
		capture drop `fin'X`mkp_x'
		gen `fin'X`mkp_x'=`fin'*`mkp_x'
		
		*interacting fin with mkp 
		reghdfe `y' `fin' `mkp_x' `fin'X`mkp_x' `othercontrol',absorb(i.period) vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, YES, Workforce composition, YES, Firm age, YES, SIC-YEAR FE, NO, Sample, `s')  
			
		
		reghdfe `y' `fin' `mkp_x' `fin'X`mkp_x' `othercontrol',absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, NO, Workforce composition, YES, Firm age, YES, SIC-YEAR FE, YES,  Sample, `s')  	
				

		} //end of yvar list 
	 
} //end of i list




**# Table 4 alternative definition of earnings & MP 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local fin fin2emp
local othercontrol lag_lg_firmage_emp  lag_male_shr lag_white_shr lag_college_shr
local cluster id1  //cluster at firm
global yvar_list lg_med_rearn lg_rpay_emp
 
local filename ${DIR_OUTPUT}\Table4
capture rm `filename'.xls 
capture rm `filename'.txt 
 
		use "${DIR_DATA}\`s'",clear    		
		foreach y of global yvar_list{ 
	
		*examine finance premium
		reghdfe `y' `fin', absorb(i.period) vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, YES, Workforce composition, NO, Firm age, NO, SIC-YEAR FE, NO, Sample,`s')  
	
		
	    local i 2_emp
	    local mkp_x lag_empshr_sic`i'  	
		capture drop `fin'X`mkp_x'
		gen `fin'X`mkp_x'=`fin'*`mkp_x'
		
		*interacting fin with mkp 
		reghdfe `y' `fin' `mkp_x' `fin'X`mkp_x' `othercontrol',absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, NO, Workforce composition, YES, Firm age, YES, SIC-YEAR FE, YES,  Sample, `s')  	
				
		} //end of yvar list 
	 
 

 
**# Table 5 & Table A4 financial vars & MP 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
global yvar_list roap lerner s_a lgs_emp lgppent lgcapx lgppent2emp lgcapx2emp
global sector_list 0
global cond_list 0   
local othercontrol lag_lg_firmage_emp  lag_male_shr lag_white_shr lag_college_shr
local cluster id1  //cluster at firm
local i 2_emp 
local mkp_x lag_empshr_sic`i'
local filename ${DIR_OUTPUT}\Table5_A4
capture rm `filename'.xls 
capture rm `filename'.txt 

		use "${DIR_DATA}\`s'",clear  
		 
		foreach g of global sector_list{ //sector group list
			 	   
				sum ${sector_groups`g'}
				ds ${sector_groups`g'}
				global group `r(varlist)'			
				 
				foreach var of global group{
					cap drop `var'X`mkp_x'
					gen `var'X`mkp_x'=`var'*`mkp_x'		
				}
						 			
				foreach c of global cond_list{						
				 foreach y of global yvar_list{
								
					reghdfe `y' `mkp_x' *X`mkp_x' $group  `othercontrol' ${cond`c'},absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin nocon
					outreg2 using "`filename'.xls", ///
					addtext( Workforce composition, YES, Firm age, YES, SIC-YEAR FE, YES,  Sample, `s') keep(`mkp_x' *X`mkp_x') 
			
				 } //end of yvar list 
				}  //end of c list
				cap drop *X`mkp_x' 	
				  
	} // end of sector group g

 

**# Table 6 inequality & MP 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
global yvar_list lg_avg_f_rearn_p90 lg_avg_f_rearn_p99 lg_avg_rearn_p66 lg_rearn_f90_10 lg_rearn_f99_1 lg_sd_rearn
local fin fin2emp
local othercontrol lag_lg_firmage_emp  lag_male_shr lag_white_shr lag_college_shr
local i 2_emp
local mkp_x lag_empshr_sic`i'  	
local cluster id1  //cluster at firm
local filename ${DIR_OUTPUT}\Table6
capture rm `filename'.xls 
capture rm `filename'.txt 

		use "${DIR_DATA}\`s'",clear    		
		foreach y of global yvar_list{ 
	    
		capture drop `fin'X`mkp_x'
		gen `fin'X`mkp_x'=`fin'*`mkp_x'
			
		reghdfe `y' `fin' `mkp_x' `fin'X`mkp_x' `othercontrol',absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext(Workforce composition, YES, Firm age, YES, SIC-YEAR FE, YES,  Sample, `s')  	
				
		} //end of yvar list 
	 
 

**# Table 7 earnings & CZ MP 
global level firmid_cz_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
global yvar_list lg_avg_rearn lg_avg_f_rearn_p90 lg_rearn_f90_10
local fin fin2emp
local othercontrol lag_lg_firmage_emp  lag_male_shr lag_white_shr lag_college_shr
local i 2_emp
local mkp_x lag_empshr_sic`i'  	
local cluster id1  //cluster at firm
local filename ${DIR_OUTPUT}\Table7
capture rm `filename'.xls 
capture rm `filename'.txt 

		use "${DIR_DATA}\`s'",clear    		
		foreach y of global yvar_list{ 
	    
		capture drop `fin'X`mkp_x'
		gen `fin'X`mkp_x'=`fin'*`mkp_x'
			
		reghdfe `y' `fin' `mkp_x' `fin'X`mkp_x' `othercontrol',absorb(i.period#i.${firm_ind}`i') vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext(Workforce composition, YES, Firm age, YES, SIC-YEAR FE, YES,  Sample, `s')  	
				
		} //end of yvar list 

**# Table 8 earnings & MP by tradable vs non-tradable (See above)


 
**# Figure A1  HHI trends 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local fin fin2emp
local filename ${DIR_OUTPUT}\FigureA1
  
		use "${DIR_DATA}\`s'",clear
	 
		tab year 
		gen p90_94=1 if year<=1994 
		gen p95_98=1 if year>=1995 & year<=1998 
		gen p99_02=1 if year>=1999 & year<=2002
		gen p03_06=1 if year>=2003 & year<=2006
		gen p07_10=1 if year>=2007 & year<=2010
		gen p11_13=1 if year>=2011 & year<=2013

		foreach var of varlist p9* p0* p1*{
			replace `var'=0 if `var'==.
		}
			 
	
		reg emphhi_sic2_emp  p9* p0* p1*   if `fin'==1,nocon
		preserve
		mat b=e(b)' // transpose e(b) into matrix b
		svmat double b,names(HHI2d_fin)
		drop period 
		gen period=_n
		keep period HHI2d_fin1
		keep if HHI2d_fin1!=.
		rename HHI2d_fin1 HHI2d_fin
		tempfile temp1
		save `temp1',replace
		restore

		reg emphhi_sic2_emp  p9* p0* p1*   if `fin'==0,nocon
		preserve
		mat b=e(b)' // transpose e(b) into matrix b
		svmat double b,names(HHI2d_nfin)
		drop period 
		gen period=_n
		keep period HHI2d_nfin1
		keep if HHI2d_nfin1!=.
		rename HHI2d_nfin1 HHI2d_nfin
		tempfile temp0
		save `temp0',replace
		restore

		clear
		use `temp0',clear 
		merge 1:1 period using `temp1',keep(3) nogen 
		gen period_fin=period-0.2
		gen period_nfin=period+0.2
		twoway (bar HHI2d_fin  period_fin, barwidth(0.4) color(gs2)) ///
			   (bar HHI2d_nfin period_nfin, barwidth(0.4) color(gs10)), ///
			   legend(label(1 "Finance ") label(2 "Non-finance")) ///
			   xlabel(1 `"1990-1994"' 2 `"1995-1998"' 3 `"1999-2002"'  4 `"2003-2006"' 5 `"2007-2010"' 6 `"2011-2013"', labsize(vsmall)) ///
			   ylabel(0.0025(0.001)0.0105,labsize(vsmall)) ///
			   ytitle("HHI (2-digit SIC)") ///
			   legen(size(vsmall)) scheme(s2color) bgcolor(white) graphregion(color(white)) name(hhi2,replace)
			   graph export "`filename'.pdf", as(pdf) replace



**# Table A1 Summary stats by subsector vs high-tech  
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local byvar fin2emp //t-test difference by `byvar'	 	
local stats_vars  "avg_rearn empshr_sic2_emp male_shr white_shr college_shr firmage_emp"  
local filename ${DIR_OUTPUT}\TableA1
capture rm `filename'.txt 	
			
		use "${DIR_DATA}\`s'",clear 
		keep if fin2emp==1 | htech==1 //compare fin vs high=tech  
		keep  `stats_vars' `byvar' $time_level $unit_level
		ttest_wo_weight `stats_vars' , by( `byvar' ) 
		esttab using `filename'.txt, append  nomtitle nonumbers noobs varwidth(25) modelwidth(22) 	star(* 0.10 ** 0.05 *** 0.01)		///	
			cells("Mean(fmt(3))  Mean_0  Mean_1  d(star pvalue(d_p))  " "sd(fmt(3) par)  sd_0(par)  sd_1(par)  d_se(par)") ///						 
			title("***Summary statistics of Sample `s',  Mean(Std) for all firms (Column 1) and by ** `byvar'  ** dummy   (Column 2: dummy=0 if it's a non-finance firm, Column 3: dummy=1 if it's a finance firm); difference and significance level between columns 2 and 3 in column 4; All variables have the same number of observations. ***") 	///
			addnotes("* p<0.10    ** p<0.05   *** p<0.01") 
		eststo clear
 
		
		
 

**# Table A2 Summary stats of public firms 	
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local byvar fin2emp //t-test difference by `byvar'	 	
local stats_vars  "roap lerner s_a s_emp firmage_emp"  
local filename ${DIR_OUTPUT}\TableA2
capture rm `filename'.txt 	
			
		use "${DIR_DATA}\`s'",clear 
		keep  `stats_vars' `byvar' $time_level $unit_level
		ttest_wo_weight `stats_vars' , by( `byvar' ) 
		esttab using `filename'.txt, append  nomtitle nonumbers noobs varwidth(25) modelwidth(22) 	star(* 0.10 ** 0.05 *** 0.01)		///	
			cells("Mean(fmt(3))  Mean_0  Mean_1  d(star pvalue(d_p))  " "sd(fmt(3) par)  sd_0(par)  sd_1(par)  d_se(par)") ///						 
			title("***Summary statistics of Sample `s',  Mean(Std) for all firms (Column 1) and by ** `byvar'  ** dummy   (Column 2: dummy=0 if it's a non-finance firm, Column 3: dummy=1 if it's a finance firm); difference and significance level between columns 2 and 3 in column 4; All variables have the same number of observations. ***") 	///
			addnotes("* p<0.10    ** p<0.05   *** p<0.01") 
		eststo clear
 		
		
		

**# Table A3 Task Scores and Worker Earnings (external codes) 
local s acs_regsample_2001_2013
local cluster pwstate2 //cluster at state here since firm is not observed in ACS
local weight [aw=per_wt] //since ACS is a survey, weight by sampling weight(perwt)*weeks worked(wkswork)*hours worked per week(uhrswork) following Autor, Dorn and Hanson (2013)
local filename ${DIR_OUTPUT}\TableA3
global yvar_list ln_hwage
capture rm `filename'.xls 
capture rm `filename'.txt 
        
		**task scores from Autor and Dorn (2013)
		use "${DIR_DATA}\`s'",clear 
		*standardize task scores
		foreach task in  task_abstract task_routine task_manual{
			cap drop sd_`task'
			egen sd_`task'=std(`task')
		}


		foreach y of global yvar_list{
			reghdfe `y' sd_* `weight', a(i.year ) cluster(`cluster') //as do not observe firm, cluster at industry
			outreg2 using "`filename'.xls", append addtext(Year FE, Yes, weight, `weight') bdec(4) sdec(4)  pdec(4) rdec(3) 

			reghdfe `y' sd_* `weight', a(i.year#i.educ i.pwstate2#i.year i.race#i.sex i.educ#c.nage2 i.educ#c.nage3) cluster(`cluster') //as do not observe firm, cluster at industry
			outreg2 using "`filename'.xls", append addtext(YearxEdu, Yes, StatexYear, Yes, Race-Sex FE, Yes, Edu functions, Yes, weight, `weight') bdec(4) sdec(4)  pdec(4) rdec(3) 	 
		}
		
		
		**task scores from Deming(2017)
		use "${DIR_DATA}\`s'",clear 
		*standardize task scores
		foreach task in math_onet1998 socskills_onet1998{
			cap drop sd_`task'
			egen sd_`task'=std(`task')
		}


		foreach y of global yvar_list{
			reghdfe `y' sd_* `weight', a(i.year ) cluster(`cluster') //as do not observe firm, cluster at industry
			outreg2 using "`filename'.xls", append addtext(Year FE, Yes, weight, `weight') bdec(4) sdec(4)  pdec(4) rdec(3) 

			reghdfe `y' sd_* `weight', a(i.year#i.educ i.pwstate2#i.year i.race#i.sex i.educ#c.nage2 i.educ#c.nage3) cluster(`cluster') //as do not observe firm, cluster at industry
			outreg2 using "`filename'.xls", append addtext(YearxEdu, Yes, StatexYear, Yes, Race-Sex FE, Yes, Edu functions, Yes, weight, `weight') bdec(4) sdec(4)  pdec(4) rdec(3) 	 
		}

 

**# Table A4 MP & PPE (see above in Table 5)

**# Table A5 Summary stats by Fin and Non-finance at CZ level 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local byvar fin2emp //t-test difference by `byvar'	 	
local stats_vars  "avg_rearn avg_f_rearn_p90 rearn_f90_10 empshr_sic2_emp firmage_emp"  
local filename ${DIR_OUTPUT}\TableA5
capture rm `filename'.txt 	
			
		use "${DIR_DATA}\`s'",clear 
		keep  `stats_vars' `byvar' $time_level $unit_level
		ttest_wo_weight `stats_vars' , by( `byvar' ) 
		esttab using `filename'.txt, append  nomtitle nonumbers noobs varwidth(25) modelwidth(22) 	star(* 0.10 ** 0.05 *** 0.01)		///	
			cells("Mean(fmt(3))  Mean_0  Mean_1  d(star pvalue(d_p))  " "sd(fmt(3) par)  sd_0(par)  sd_1(par)  d_se(par)") ///						 
			title("***Summary statistics of Sample `s',  Mean(Std) for all firms (Column 1) and by ** `byvar'  ** dummy   (Column 2: dummy=0 if it's a non-finance firm, Column 3: dummy=1 if it's a finance firm); difference and significance level between columns 2 and 3 in column 4; All variables have the same number of observations. ***") 	///
			addnotes("* p<0.10    ** p<0.05   *** p<0.01") 
		eststo clear

**# Table A6 Industry concentration (2d and 3d) and worker earnings 
global level firmid_qtr
define_panel
local s ${level}_regsample_${year_min}_${year_max} 
local fin fin2emp
local othercontrol lag_lg_firmage_emp  lag_male_shr lag_white_shr lag_college_shr
local cluster id1  //cluster at firm
global yvar_list lg_avg_rearn
 
local filename ${DIR_OUTPUT}\TableA6
capture rm `filename'.xls 
capture rm `filename'.txt 

use "${DIR_DATA}\`s'",clear    		
foreach y of global yvar_list{
 
	
	foreach i in 2_emp 3_emp{ //defining market using i-digit of SIC
	
	    local mkp_x lag_emphhi_sic`i'	
		capture drop `fin'X`mkp_x'
		gen `fin'X`mkp_x'=`fin'*`mkp_x'
			 
		reghdfe `y'   `mkp_x'  `othercontrol',absorb(i.period) vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, YES, Workforce composition, YES, Firm age, YES, Sample, `s')  drop(`othercontrol')
			
		
		reghdfe `y' `fin' `mkp_x' `fin'X`mkp_x' `othercontrol',absorb(i.period) vce(cluster `cluster') keepsin
		outreg2 using "`filename'.xls", ///
		addtext( YearxQuarterFE, YES, Workforce composition, YES, Firm age, YES, Sample, `s')  drop(`othercontrol') 	
				

		} //end of yvar list 
	 
} //end of i list


log close
